<?php
if(isset($this->request->data) && !empty($this->request->data)){
    $this->Paginator->options(array('url' => $this->request->data['Customer']));
}
$pageOption = $this->Paginator->params();
$sN = "Customer";
?>
<div id="content">
    <div id="page-heading">
        <h1>Customers interested in <?=$interest['Interest']['name']?> </h1>
    </div>
    <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
        <tr>
            <th rowspan="3" class="sized">
                <?php echo $this->Html->image('../images/shared/side_shadowleft.jpg', array('width' => '20', 'height' => '300', 'alt' => '')); ?>
            </th>
            <th class="topleft"></th>
            <td id="tbl-border-top">&nbsp;</td>
            <th class="topright"></th>
            <th rowspan="3" class="sized">
                <?php echo $this->Html->image('../images/shared/side_shadowright.jpg', array('width' => '20', 'height' => '300', 'alt' => '')); ?>
            </th>
	</tr>
	<tr>
            <td id="tbl-border-left"></td>
            <td>
                <div id="content-table-inner">
                    <?php echo $this->Session->flash();?>
                    <script type="text/javascript">
                        $(document).ready(function() {
                            $('#check-all').change(function(){
                                if($('#check-all').attr('checked')){
                                    $('.customer').each(function(){
                                        $(this).attr('checked', true);
                                    });
                                }else{
                                    $('.customer').each(function(){
                                        $(this).attr('checked', false);
                                    });
                                }
                            });
                            $('#action').change(function(){
                                if($(this).val()=='send_message'){
                                    url = "<?php echo $this->Html->url(array('controller'=>'messages','action'=>'send','admin'=>true)); ?>";
                                    var kt = 1;
                                    check = check_customer();
                                    if(check != ''){
                                        url = url + '/'+check;
                                    }else{
                                        var kt=0;
                                        alert("Please choose a customer to send message");
                                        reset_option();
                                    }
                                    if(kt==1){
                                        window.location = url;
                                        //alert('This will be build later!');
                                        reset_option();
                                    }
                                }else if($(this).val()=='send_voucher'){
                                    url = "<?php echo $this->Html->url(array('controller'=>'customers','action'=>'send_voucher','admin'=>true)); ?>";
                                    var kt = 1;
                                    check = check_customer();
                                    if(check != ''){
                                        url = url + '/'+check;
                                    }else{
                                        var kt=0;
                                        alert("Please choose a customer to send voucher ?");
                                        reset_option();
                                    }
                                    if(kt==1){
                                        window.location = url;
                                        //alert('This will be build later!');
                                        //reset_option();
                                    }
                                }
                            });
                            $('.placeholder').placeplaceholder();
                        });
                        function reset_option(){
                                $('#action').val('').trigger("liszt:updated");
                            }
                        function check_customer(){
                            check = new Array();
                            $('.customer').each(function(){
                                if($(this).attr('checked')){
                                    check.push($(this).val());
                                }
                            });
                            return check;
                        }
                    </script>
                    <div id="table-content">
                        <table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
                            <tr>
                                <th class="table-header-repeat line-left">
                                    <input id="check-all" type="checkbox"/>
                                </th>
                                <th class="table-header-repeat line-left">
                                    Name
                                </th>
                                <th class="table-header-repeat line-left">
                                    Balance
                                </th>
                                <th class="table-header-repeat line-left">
                                    Point
                                </th>
                                <th class="table-header-repeat line-left">
                                    Email
                                </th>
                                <th class="table-header-repeat line-left">
                                    Mobile
                                </th>
                                <th class="table-header-repeat line-left">
                                    Created
                                </th>
                                <th class="table-header-repeat line-left">Options</th>
                            </tr>
                            <?php 
                                $alt = 0;
                                foreach($values as $value): 
                                    $alt_row = $alt % 2;
                                    $alt_rows = ($alt_row == 1)? 'alternate-row': '';
                            ?>
                            <tr class="<?php echo $alt_rows; ?>">
                                <td>
                                    <input type="checkbox" class="customer" value="<?=$value[$sN]['id']?>">        
                                </td>
                                <td>
                                    <?php echo $value[$sN]['f_name']." ".$value[$sN]['l_name']; ?>
                                </td>
                                <td>
                                    <?php echo $value[$sN]['balance']; ?>
                                </td>
                                <td>
                                    <?php echo $value[$sN]['point']; ?>
                                </td>
                                <td>
                                    <?php echo $value[$sN]['email']; ?>
                                </td>
                                <td>
                                    <?php echo $value[$sN]['mobile']; ?>
                                </td>
                                <td>
                                    <?php echo $value[$sN]['created']; ?>
                                </td>
                                <td class="options-width">
                                    
                                </td>
                            </tr>
                            <?php 
                                $alt++;
                                endforeach; 
                            ?>
                        </table>
			<div class="clear"></div>
                        <? if($pageOption['pageCount'] > 1): ?>	
                        <table border="0" cellpadding="0" cellspacing="0" id="paging-table">
                            <?php echo $this->element('pagination');?>       
                        </table>
                        <? endif; ?>	
                        <div style="padding-right: 10px;padding-bottom: 20px;float: left">
                            <select id="action" class="chosen">
                                <option value="">Choose an action</option>
                                <option value="send_message">Send Message</option>
                                <option value="send_voucher">Send Voucher</option>
                            </select>
                        </div>
                    </div>
                    <div class="clear"></div>
                </div>
            </td>
            <td id="tbl-border-right"></td>
        </tr>
        <tr>
            <th class="sized bottomleft"></th>
            <td id="tbl-border-bottom">&nbsp;</td>
            <th class="sized bottomright"></th>
        </tr>
    </table>
    <div class="clear">&nbsp;</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function(){
            jQuery("#customerMenu").addClass('current');
});
</script>